﻿using System.Linq.Expressions;
using CoreEx.Database.Metadata;

namespace CoreEx.Database.Linq
{
    /// <summary>
    /// Represents an option to eager load a navigation propertry.  
    /// </summary>
    public class LoadOption
    {
        /// <summary>
        /// Gets or sets the <see cref="LambdaExpression"/> that describes the member to be loaded.
        /// </summary>
        /// <value></value>
        /// <remarks>
        /// The <see cref="LambdaExpression"/> may contain a <see cref="MethodCallExpression"/> for
        /// enumerable load options.
        /// </remarks>
        public LambdaExpression LoadExpression { get; set; }

        /// <summary>
        /// Gets or sets a <see cref="bool"/> values that indicates if the relation
        /// described by this <see cref="LoadOption"/> has been loaded.
        /// </summary>
        /// <value></value>
        public bool IsLoaded { get; set; }

        /// <summary>
        /// Gets or sets the <see cref="IPropertyMappingInfo"/> instance that applies to the navigation property.
        /// </summary>        
        /// <value></value>
        public IPropertyMappingInfo PropertyMapping { get; set; }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public override string ToString()
        {
            if (LoadExpression != null)
                return LoadExpression.ToString();
            return base.ToString();
        }
    }
        

}
